package com.cfs.svcimpl.bz;

import java.util.List;

import com.cfs.dao.bz.InformationDao;
import com.cfs.po.bz.AppInfo;
import com.cfs.po.bz.Information;
import com.cfs.svc.bz.InformationService;
import com.cfs.vo.Condition;
import com.cfs.vo.Pager;
import com.cfs.vo.Res;

public class InformationServiceImpl implements InformationService  {

	private InformationDao dao;
	
	public InformationDao getDao() {
		return dao;
	}

	public void setDao(InformationDao dao) {
		this.dao = dao;
	}


	public Information get(Long id) {
		return dao.get(id);
	}

	public Long add(Information info) {
		Long n = dao.insert(info);
		System.out.println("RETURN Information NUM: " + n + " ID:" + info.getId() );
		return info.getId();
	}

	public Integer deleteById(Long id) {
		return dao.delete(id);
	}

	public Long update(Information info) {
		return dao.update(info);
	}

	public Integer release(Information info) {
		Integer n = dao.release(info);
		if (n == 1) {
			n = dao.insertRelease(info);
		}
		return n;
	}

	public List<Information> query(Long col_id, String terminal) {		
		return dao.query(col_id, terminal);
	}

	public List<Information> list(Condition c) {
		return dao.list(c);
	}

	@Override
	public Res<Information> listP(Condition c) {
		Res<Information> res = new Res<Information>();
		try{
			Pager p = c.getP() == null ? new Pager() : c.getP();
			p.resetTotalR(dao.queryRows(c));
			List<Information> list = dao.list(c);

			res.setP(p);
			res.setList(list);

		}catch(Exception e){
			res.setCode(-1);
			res.setMsg(e.getLocalizedMessage());
			e.printStackTrace();
		}
		
		return res;
	}

}
